import 'package:get/get.dart';
import 'package:mall/constant/app_parameters.dart';
import 'package:mall/ui/page/404/not_find_page.dart';
import 'package:mall/ui/page/goods/category/category_goods_page.dart';
import 'package:mall/ui/page/goods/fill_in_order_page.dart';
import 'package:mall/ui/page/goods/detail/goods_detail_page.dart';
import 'package:mall/ui/page/goods/home_category_goods_page.dart';
import 'package:mall/ui/page/goods/order/after_sale_page.dart';
import 'package:mall/ui/page/goods/order/logistics_page.dart';
import 'package:mall/ui/page/goods/search/search_goods_page.dart';
import 'package:mall/ui/page/goods/search/search_result_page.dart';
import 'package:mall/ui/page/goods/submit_success_page.dart';
import 'package:mall/ui/page/home/brand_detail_page.dart';
import 'package:mall/ui/page/home/home_page.dart';
import 'package:mall/ui/page/home/main_page.dart';
import 'package:mall/ui/page/home/project_selection_detail_page.dart';
import 'package:mall/ui/page/login/login_password.dart';
import 'package:mall/ui/page/login/login_phone.dart';
import 'package:mall/ui/page/login/register_page.dart';
import 'package:mall/ui/page/mine/about_us_page.dart';
import 'package:mall/ui/page/mine/address/address_detail_page.dart';
import 'package:mall/ui/page/mine/address/address_page.dart';
import 'package:mall/ui/page/mine/collect/collect_page.dart';
import 'package:mall/ui/page/mine/coupon/coupon_page.dart';
import 'package:mall/ui/page/mine/feedback_page.dart';
import 'package:mall/ui/page/mine/foot_print/foot_print_page.dart';
import 'package:mall/ui/page/goods/order/order_detail_page.dart';
import 'package:mall/ui/page/goods/order/order_page.dart';
import 'package:mall/ui/page/mine/user_info/user_info.dart';
import 'package:mall/ui/page/square/square_pub_page.dart';
import 'package:mall/ui/widgets/webview_widget.dart';

import 'route_names.dart';

/// 路由页面源
final List<GetPage> routePages = [
  _splashPage(),
  _homePage(),
  _notFindPage(),
  _categoryGoodsPage(),
  _goodsDetailPage(),
  _loginPhonePage(),
  _loginPasswordPage(),
  _registerPage(),
  _fillInOrderPage(),
  _addressPage(),
  _editAddressPage(),
  _couponPage(),
  _searchGoodsPage(),
  _webViewPage(),
  _brandDetailPage(),
  _projectSelectionDetailPage(),
  _collectPage(),
  _aboutUsPage(),
  _feedBackPage(),
  _footPrintPage(),
  _submitSuccessPage(),
  _homeCategoryGoodsPage(),
  _orderPage(),
  _orderDetailPage(),
  _searchResultPage(),
  _squarePubPage(),
  _userInfoPage(),
  _logisticsPage(),
  _afterSalePage(),
];




//首页
GetPage _homeCategoryGoodsPage() => GetPage(
      name: MobileRouteNames.homeCategoryGoods,
      page: () {
        final title = Get.parameters["title"];
        final id = int.tryParse(Get.parameters["id"] ?? '0') ?? 0;
        return HomeCategoryGoodsPage(title!, id);
      },
    );

GetPage _brandDetailPage() => GetPage(
      name: MobileRouteNames.brandDetail,
      page: () {
        final title = Get.parameters["titleName"];
        final id = int.tryParse(Get.parameters["id"] ?? '0') ?? 0;
        return BrandDetailPage(title!, id);
      },
    );

GetPage _projectSelectionDetailPage() => GetPage(
      name: MobileRouteNames.projectSelectionDetail,
      page: () {
        final id = int.tryParse(Get.parameters["id"] ?? '0') ?? 0;
        return ProjectSelectionDetailView(id);
      },
    );


GetPage _homePage() => GetPage(
      name: MobileRouteNames.home,
      page: () => HomePage(),
    );



//商品
GetPage _submitSuccessPage() => GetPage(
      name: MobileRouteNames.submitSuccess,
      page: () => SubmitSuccessPage(),
    );


GetPage _footPrintPage() => GetPage(
      name: MobileRouteNames.footPrint,
      page: () => FootPrintPage(),
    );

GetPage _collectPage() => GetPage(
      name: MobileRouteNames.collect,
      page: () => CollectPage(),
    );


GetPage _couponPage() => GetPage(
      name: MobileRouteNames.coupon,
      page: () => CouponPage(),
    );

GetPage _goodsDetailPage() => GetPage(
      name: MobileRouteNames.goodsDetail,
      page: () {
        final goodsId = int.tryParse(Get.parameters[AppParameters.GOODS_ID] ?? '0') ?? 0;
        return GoodsDetailPage(goodsId);
      },
    );
//售后
GetPage _afterSalePage() => GetPage(
      name: MobileRouteNames.afterSale,
      page: () => AfterSalePage(),
    );

GetPage _fillInOrderPage() => GetPage(
      name: MobileRouteNames.fillInOrder,
      page: () {
        // final cartId = int.tryParse(Get.parameters[AppParameters.CART_ID] ?? '0') ?? 0;
        return FillInOrderPage();
      },
    );

GetPage _categoryGoodsPage() => GetPage(
      name: MobileRouteNames.categoryGoods,
      page: () {
        final categoryName = Get.parameters[AppParameters.CATEGORY_NAME];
        final categoryId = int.tryParse(Get.parameters[AppParameters.CATEGORY_ID] ?? '0') ?? 0;
        return CategoryGoodsPage(categoryName!, categoryId);
      },
    );



// 订单
GetPage _orderPage() => GetPage(
      name: MobileRouteNames.orderPage,
      page: () {
        final initIndex = int.tryParse(Get.parameters["initIndex"] ?? '0') ?? 0;
        return OrderPage(initIndex);
      },
    );

GetPage _orderDetailPage() => GetPage(
      name: MobileRouteNames.orderDetailPage,
      page: () {
        final orderId = int.tryParse(Get.parameters["orderId"] ?? '0') ?? 0;
        return OrderDetailPage(orderId);
      },
    );

//物流

GetPage _logisticsPage() => GetPage(
      name: MobileRouteNames.logistics,
      page: () {
        return LogisticsPage();
      },
    );

//搜索
GetPage _searchGoodsPage() => GetPage(
      name: MobileRouteNames.searchGoods,
      page: () => SearchGoodsPage(),
    );

GetPage _searchResultPage() => GetPage(
      name: MobileRouteNames.searchResult,
      page: () => SearchResultPage(),
    );

//地址
GetPage _addressPage() => GetPage(
      name: MobileRouteNames.address,
      page: () {
        return AddressViewPage();
      },
    );

GetPage _editAddressPage() => GetPage(
      name: MobileRouteNames.editAddress,
      page: () {
        return AddressDetailPage();
      },
    );

//广场
GetPage _squarePubPage() => GetPage(
      name: MobileRouteNames.squarePubPage,
      page: () => SquarePubPage(),
    );



//登录和注册

GetPage _loginPhonePage() => GetPage(
      name: MobileRouteNames.login_phone,
      page: () => LoginWithPhone(),
    );
GetPage _loginPasswordPage() => GetPage(
      name: MobileRouteNames.login_password,
      page: () => LoginWithPassword(),
    );

GetPage _registerPage() => GetPage(
      name: MobileRouteNames.register,
      page: () => RegisterPage(),
    );


//我的

GetPage _userInfoPage() => GetPage(
      name: MobileRouteNames.userInfo,
      page: () {
        return UserInfoPage();
      },
    );


//客户端

GetPage _aboutUsPage() => GetPage(
      name: MobileRouteNames.aboutUs,
      page: () => AboutUsPage(),
    );

GetPage _feedBackPage() => GetPage(
      name: MobileRouteNames.feedBack,
      page: () => FeedBackPage(),
    );

GetPage _webViewPage() => GetPage(
      name: MobileRouteNames.webView,
      page: () {
        final title = Get.parameters["titleName"];
        final url = Get.parameters["url"];
        return WebViewPage(url!, title!);
      },
    );

GetPage _notFindPage() => GetPage(
      name: '/404',
      page: () => NotFindPage(),
    );

GetPage _splashPage() => GetPage(
      name: MobileRouteNames.splash,
      page: () => MainPage(),
    );


